package ds.tree;


public class DoubleTree {
	private static class TreeNode{
		int value;
		TreeNode left = null;
		TreeNode right = null;
		
		TreeNode(int val){
			this.value = val;
		}
		
		public String toString(){
			return String.valueOf(value);
		}
	}
	public void doubleTree(TreeNode node) {
		if(node == null){
			return;
		}
		doubleTree(node.left);
		doubleTree(node.right);
		
		TreeNode oldleft = node.left;
		TreeNode newnode = new TreeNode(node.value);
		node.left = newnode;
		newnode.left = oldleft;
		
	}
	private static TreeNode tree(){
		TreeNode A = new TreeNode(1);
		TreeNode B = new TreeNode(2);
		TreeNode C = new TreeNode(3);
//		TreeNode D = new TreeNode(4);
//		TreeNode E = new TreeNode(5);
		
		A.left = B;
		A.right = C;
//		B.left = D;
//		B.right = E;
		
		return A;
	}	
	private void inorder(TreeNode node){
		if(node == null){
			return;
		}
		inorder(node.left);
		System.out.print(node + " ");
		inorder(node.right);
	}
	public static void main(String[] args) {
		DoubleTree dTree = new DoubleTree();
		TreeNode node = tree();
		dTree.inorder(node);
		dTree.doubleTree(node);
		dTree.inorder(node);
	}

}
